<?php
$Basedir = dirname(__FILE__);
$field_id = rex_request('field_id', 'int');
$id = rex_request('id', 'int');

//------------------------------> Eintragsliste
if ($func == '')
{
	$list = new rex_list('SELECT id,haendler_name,haendler_name_zusatz,haendler_strasse,haendler_land,haendler_plz,haendler_stadt,haendler_status FROM rex_290_haendler',200);
	
	$imgHeader = '<a href="'. $list->getUrl(array('func' => 'add')) .'"><img src="media/metainfo_plus.gif" alt="add" title="add" /></a>';
	
	$list->setColumnSortable('haendler_name');
	$list->setColumnSortable('haendler_name_zusatz');
	$list->setColumnSortable('haendler_strasse');
	$list->setColumnSortable('haendler_land');
	$list->setColumnSortable('haendler_plz');
	$list->setColumnSortable('haendler_stadt');
	$list->setColumnSortable('haendler_status');	



	$list->addColumn(	$imgHeader, 
						'<img src="media/metainfo.gif" alt="field" title="field" />', 
						0, 
						array('<th class="rex-icon">###VALUE###</th>',
								'<td class="rex-icon">###VALUE###</td>')
					);					
	$list->setColumnParams	(	$imgHeader, 
								array('func' => 'edit', 'id' => '###id###')
							);
	
	
	$list->setColumnLabel('id', "ID");
	$list->setColumnLabel('haendler_name', 'Name der Firma');	
	$list->setColumnLabel('haendler_name_zusatz', 'Namenszusatz');
	$list->setColumnLabel('haendler_strasse', 'Stra&szlig;e');
	$list->setColumnLabel('haendler_land', 'Land');
	$list->setColumnLabel('haendler_plz', 'PLZ');
	$list->setColumnLabel('haendler_stadt', 'Stadt');
	$list->setColumnLabel('haendler_status', 'On/Offline');

	
	$list->setColumnLayout	(	'id',
								array('<th class="rex-icon">###VALUE###</th>','<td class="rex-icon">###VALUE###</td>')
							);
	$list->setColumnParams('haendler_name', array('func' => 'edit', 'id' => '###id###'));
	$list->show();
}
//------------------------------> Formular
elseif ($func == 'edit' || $func == 'add')
{	$form = new a290_rex_form('rex_290_haendler',"Daten","id=".$id,"post",false);

	$field = &$form->addTextField('haendler_name');
    $field->setLabel("Name der Firma");
    
    $field = &$form->addTextField('haendler_name_zusatz');
    $field->setLabel("Namenszusatz");
    
    $field = &$form->addTextField('haendler_abteilung');    
    $field->setLabel("Abteilung");
    
    $field = &$form->addTextField('haendler_telefon');    
    $field->setLabel("Telefon");
    
    $field = &$form->addTextField('haendler_fax');    
    $field->setLabel("Fax");
    
   
    $field = &$form->addTextField('haendler_email');    
    $field->setLabel("E-Mail");
    
    $field = &$form->addTextField('haendler_homepage');    
    $field->setLabel("Homepage");
	
    $field = &$form->addTextField('haendler_strasse');    
    $field->setLabel("Stra&szlig;e");
    
	#postfach
	$field = &$form->addTextField('haendler_postfach');    
    $field->setLabel("Postfach");
		    
    $field = &$form->addTextField('haendler_plz');    
    $field->setLabel("PLZ");

    $field = &$form->addTextField('haendler_stadt');    
    $field->setLabel("Stadt");


    $field = &$form->addTextField('haendler_land');    
    $field->setLabel("Land");
	

    $field = &$form->addTextAreaField('haendler_sonstiges');    
    $field->setLabel("Sonstiges");

	$field =& $form->addSelectField('haendler_status');
    $field->setLabel("Status");
	$select =& $field->getSelect();
	$select->setSize(1);
	$select->addOption('Online',1);
	$select->addOption('Offline',0);
	$select->setAttribute('style','width:100px');
	
	//standartwert : 1
	if ($field->getValue()=="")
	{	$field->setValue(1);
	}
	
	
	
	// select box for Branche
	$field = &$form->addSelectField('r_haendler_branche');
	$field->setLabel("Branche");
	$select =& $field->getSelect();
	$select->setSize(1);
    $qry = 'SELECT haendler_branche as label,id FROM '.$REX['TABLE_PREFIX'].'290_branchen';
   	$select->addSqlOptions($qry);
	
	// select box for Gebiete
	$field = &$form->addSelectField('r_haendler_gebiete');
	$field->setAttribute('multiple','multiple');
	$field->setLabel("Gebiet");
	$select =& $field->getSelect();
	$select->setSize(5);
    $qry = 'SELECT haendler_gebiet as label,id FROM '.$REX['TABLE_PREFIX'].'290_gebiete';
   	$select->addSqlOptions($qry);
   

	# logo
	$field = &$form->addMediaField('haendler_logo');
	$field->setLabel("");	
	$field->setPrefix('<label style="float:none;">Logo ausw&auml;hlen</label>');

    

    // select box for orte
    /*
	$field = &$form->addSelectField('ort');
	$field->setLabel("Ort");
	$select =& $field->getSelect();
	$select->setSize(1);
    $qry = 'SELECT ort as label,id FROM rex_vorteile_orte order by ort asc';
   	$select->addSqlOptions($qry);
    
    $field = &$form->addTextAreaField('beschreibung');
    $field->setLabel("Beschreibung");
    $field = &$form->addTextField('link');
    $field->setLabel("Link");
    $field->setSuffix('	<a href="#" onclick="openREXMedia(2,\'\');return false;"><img src="media/file_open.gif" /></a>	');
	$field->setAttribute('id','REX_MEDIA_2');
    $field->setAttribute('style','width:478px');

    // select box for sparkassen
	$field = &$form->addSelectField('sparkasse');
	$field->setLabel("Sparkasse");
	$select =& $field->getSelect();
	$select->setSize(1);
    $qry = 'SELECT sparkasse as label,id FROM rex_vorteile_sparkasse order by sparkasse asc';
   	$select->addSqlOptions($qry);
    
    
    // aktiv yes/no
	$field =& $form->addSelectField('aktiv');
    $field->setLabel("Anzeigen");
   
    $select =& $field->getSelect();
    $select->setSize(1);
    $select->addOption('Ja',1);
    $select->addOption('Nein',0);
    $select->setAttribute('style','width:100px');

    //standartwert : 1
    if ($field->getValue()=="")
    {	$field->setValue(1);
    }
   	*/
	if($func == 'edit')
    {	$form->addParam('id', $id);
    }

	
	
	$form->show();
	
}

?>